package main

import (
	"google.golang.org/grpc"
	"google.golang.org/grpc/grpclog"
	pb "../../proto/hello"
	"golang.org/x/net/context"
	"fmt"
	"google.golang.org/grpc/credentials"
)

const (
	Addres = "127.0.0.1:50052"
)

func main() {

	creds, err := credentials.NewClientTLSFromFile("src/grpc/demo/keys/server.pem", "server name")
	if err != nil {
		grpclog.Fatalf("Failed to create TLS credentials %v", err)
	}

	conn, err := grpc.Dial(Addres, grpc.WithTransportCredentials(creds))

	if err != nil {
		grpclog.Fatalln(err)
	}

	defer conn.Close()

	c := pb.NewHelloClient(conn)

	req := &pb.HelloRequest{Name: "grpc"}

	res, err := c.SayHello(context.Background(), req)

	if err != nil {
		grpclog.Fatalln(err)
	}

	fmt.Println(res.Message)
}
